// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Quran.java
package canvas;

import app.AgentWorker;
import app.Hyperlink;
import app.MenuElement;
import app.quranMenu;
import app.quranPage;
import ui.BrowseCanvas;
import ui.Element;
import ui.MenuBar;
import ui.Page;
import ui.PageListener;

import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.midlet.MIDlet;

// Referenced classes of package mquran:
//            splashQuran, QuranCanvas, MenuBarQuran, LockedCanvas
public class Quran extends MIDlet
        implements PlayerListener, PageListener {

    static void PlaySound(String ayat) {
        //soundPlayer.addQueue(ayat);
    }

    static void StopSound() {
        //soundPlayer.stopAll();
    }

    //private AgentDrawer agent;
    public Quran() {
        locked = true;
        judul = null;
        KEYDOWN = -2;
        TRIGHT = -4;
        TLEFT = -3;
        BrowseCanvas.KEYCENTER = -5;
        BrowseCanvas.KEYUP = -1;
        BrowseCanvas.KEYDOWN = -2;
        BrowseCanvas.TRIGHT = -4;
        BrowseCanvas.TLEFT = -3;
        BrowseCanvas.KEYSOFTLEFT = -6;
        BrowseCanvas.KEYSOFTRIGHT = -7;
        me = this;
    }

    public final void startApp() {
        if (display == null) {
            display = Display.getDisplay(this);
            display.setCurrent(new splashQuran());
            pages = new Vector();
            browser = new BrowseCanvas(display);
            agent = new AgentWorker();
            //soundPlayer = new SoundPlayer();
            //agent = new AgentDrawer();
            String a = getMCC().trim();
            String b = getMNC().trim();
            if (b.length() > 2) {
                b = b.substring(0, 2);
            }
            if (a.length() < 1 || b.length() < 1) {
                locked = true;
            } else if (Integer.parseInt(a) == 510 && Integer.parseInt(b.trim()) == 8) {
                locked = false;
            }
            Runnable r = new Runnable() {

                public void run() {
                    try {
                        Thread.sleep(2000L);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    showMenuUtama();
                }
            };
            (new Thread(r)).start();
        }
    }

    public void showMenuUtama() {
        qurancanvas = new QuranCanvas(display, this);
        System.out.println("######### initial #############");
        qurancanvas.init();
        System.out.println("######### Display  #############");
        display.setCurrent(qurancanvas);
        qurancanvas.openSurah(36, 0);

    }

    public static Displayable getCurrent() {
        return display.getCurrent();
    }

    public void openIndex(int pilihSurat, int pilih) {
        System.out.println("######### Masuk Open index  #############");
        qurancanvas = new QuranCanvas(display, this);
        System.out.println("######### initial #############");
        qurancanvas.init();
        System.out.println("######### Display  #############");
        display.setCurrent(qurancanvas);
        System.out.println("######### open Surah  #############");
        qurancanvas.openSurah(pilihSurat, pilih);
    }

    public void openPendahuluan() {
        qurancanvas = new QuranCanvas(display, this);
        qurancanvas.init();
        display.setCurrent(qurancanvas);
        qurancanvas.openSurah(115, 0);
    }

    public void exitMIDlet() {
        display.setCurrent(null);
        exit();
    }

    public final void pauseApp() {
        qurancanvas.hideNotify();
    }

    public final void destroyApp(boolean flag1) {
        this.notifyDestroyed();
    }

    public static void exit() {
        me.destroyApp(true);
        me.notifyDestroyed();
        me = null;
    }

    public void playerUpdate(Player player1, String s, Object obj) {
    }

    public static void show(Displayable disp) {
        display.setCurrent(disp);
    }

    public void onMenu(MenuBarQuran menuBar, int selected, String caption) {
        if (menuBar == qurancanvas.menuIndex) {
            if (caption.equals("Buka")) {
                qurancanvas.openSurah(0, 0);
            } else if (caption.equals("Menu Utama")) {
                showMenuUtama();
            } else if (caption.equals("Pendahuluan")) {
                showPage("pendahuluan.txt", null);
            } else if (caption.equals("Bantuan")) {
                showPage("bantuan.txt", null);
            } else if (caption.equals("Tentang")) {
                showPage("tentang.txt", null);
            } else //if(caption.equals("Buka Bookmark"))
            //    qurancanvas.gotoBookmark();
            //else
            if (caption.equals("Keluar")) {
                exit();
            }
        } else if (caption.equals("Index Surah")) {
            qurancanvas.gotoIndex();
        } else if (caption.equals("Menu Utama")) {
            showMenuUtama();
        } else if (caption.equals("Pendahuluan")) {
            showPage("pendahuluan.txt", null);
        } else if (caption.equals("Bantuan")) {
            showPage("bantuan.txt", null);
        } else if (caption.equals("Tentang")) {
            showPage("tentang.txt", null);
        } else //if(caption.equals("Simpan Bookmark"))
        //    qurancanvas.saveBookmark();
        //else
        if (caption.equals("Ke Ayat")) {
            qurancanvas.verse();
        } else if (caption.equals("Awal")) {
            qurancanvas.gotoStart();
        } else if (caption.equals("Akhir")) {
            qurancanvas.gotoEnd();
        }
    }

    public static String getMCC() {
        String out = "";
        try {
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("phone.mcc");
            }
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("com.nokia.mid.countrycode");
            }
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("com.sonyericsson.net.mcc");
            }
            if ((out == null || out.equals("null") || out.equals("")) && (out == null || out.equals("null") || out.equals(""))) {
                out = System.getProperty("mcc");
            }
        } catch (Exception e) {
            return out != null ? out : "";
        }
        return out != null ? out : "";
    }

    public static String getMNC() {
        String out = "";
        try {
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("phone.mnc");
            }
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("com.nokia.mid.networkid");
            }
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("com.sonyericsson.net.mnc");
            }
            if (out == null || out.equals("null") || out.equals("")) {
                out = System.getProperty("mnc");
            }
        } catch (Exception e) {
            return out != null ? out : "";
        }
        return out != null ? out : "";
    }

    public void onMenu(Page src, int menu, String caption) {
        quranPage page = (quranPage) src;
        if (page.url.startsWith("index")) {
            System.out.println("Content Atas");
            switch (menu) {
                case 0: // '\0'
                    showPage("bantuan.txt", null);
                    break;

                case 1: // '\001'
                    showPage("tentang.txt", null);
                    break;

                case 2: // '\002'
                    exitMIDlet();
                    break;
            }
        } else {
            System.out.println("Content Bawah");
            switch (menu) {
                case 0: // '\0'
                    showMenuUtama();
                    break;

                case 1: // '\001'
                    showPage("pendahuluan.txt", null);
                    break;

                case 2: // '\002'
                    showPage("bantuan.txt", null);
                    break;

                case 3: // '\003'
                    showPage("tentang.txt", null);
                    break;

                case 4: // '\004'
                    exitMIDlet();
                    break;
            }
        }
    }

    public void showPage(String url, Integer top) {
        quranPage p = new quranPage(browser, url, this);
        System.out.println("URL : " + url);
        if (browser.getPage() != null) {
            pages.addElement(browser.getPage());
        }
        if (url.startsWith("index")) {
            if (menuDepan == null) {
                Vector v = new Vector();
                v.addElement("Bantuan");
                v.addElement("Tentang");
                v.addElement("Keluar");
                menuDepan = new MenuBar("Menu", this, v, p);
            }
            p.setMenu(menuDepan);
        } else {
            if (menuContent == null) {
                Vector v = new Vector();
                v.addElement("Menu Utama");
                v.addElement("Pendahuluan");
                v.addElement("Bantuan");
                v.addElement("Tentang");
                v.addElement("Keluar");
                menuContent = new MenuBar("Menu", this, v, p);
            }
            p.setMenu(menuContent);
        }
        display.setCurrent(browser);
        browser.judulContent = judul;
        browser.showPage(p, 0);
        cur_url = "/data/" + url;

        //agent.draw(cur_url, p);
        agent.addQueue(cur_url, p, top);
    }

    public void onItemClick(Page src, Element element, int index) {
        System.out.println("Masuk onItemClick index : " + index);
        if (element instanceof Hyperlink) {
            Hyperlink new_name = (Hyperlink) element;
            judul = new_name.url;
            if (new_name.url.startsWith("http")) {
                try {
                    platformRequest(new_name.url);
                } catch (ConnectionNotFoundException e) {
                    e.printStackTrace();
                }
            } else {
                showPage(new_name.url, null);
            }
        } else if (element instanceof MenuElement) {
            MenuElement new_name = (MenuElement) element;
            judul = new_name.url;
            if (new_name.url.equals("exit")) {
                exitMIDlet();
            } else if (new_name.url.equals("index_quran")) {
                openIndex(78, 1);
            } else if (new_name.url.equals("pendahuluan.txt")) {
                openIndex(1, 0);
            } else if (new_name.url.equals("bantuan.txt")) {
                openIndex(79, 2);
            } else if (new_name.url.equals("tentang.tx")) {
                openIndex(80, 0);
            } else {
                showPage(new_name.url, null);
            }
        }
    }

    public void onSoftRightMenu(Page page) {
        agent.stopAll();
        System.out.println("Doahusna.onSoftRightMenu():" + pages.size());
        if (pages.size() > 0) {
            if (pages.size() == 1) {
                browser.judulContent = "menu";
            } else {
                browser.judulContent = "xxx";
            }
            System.out.println("judul : " + browser.judulContent);
            int last = pages.size() - 1;
            Page p = (Page) pages.elementAt(last);
            pages.removeElementAt(last);
            browser.showPage(p, 0);
        } else {
            exitMIDlet();
        }
    }

    public void onSoftLeftMenu(Page page, int menu) {
        agent.stopAll();
        System.out.println("Doahusna.onSoftLeftMenu():" + pages.size());
        switch (menu) {
            case 0: // '\0'
                showPage("pendahuluan.txt", null);
                break;

            case 1: // '\001'
                openIndex(1, 0);
                break;

            case 2: // '\002'
                showPage("bantuan.txt", null);
                break;

            case 3: // '\003'
                showPage("tentang.txt", null);
                break;

            case 4: // '\004'
                exitMIDlet();
                break;
        }
        if (pages.size() == 0) {
            browser.judulContent = "menu";
        } else {
            browser.judulContent = "xxx";
        }
    }

    public void onMessageBox(int i) {
    }
    static Quran me;
    public QuranCanvas qurancanvas;
    private LockedCanvas lockedcanvas;
    BrowseCanvas browser;
    AgentWorker agent;
    //public static SoundPlayer soundPlayer;
    quranMenu pagemnu;
    Vector pages;
    private MenuBar menuIndex;
    private MenuBar menuDepan;
    private MenuBar menuContent;
    public static Display display;
    public static final int KEYSOFTRIGHT = -7;
    public static final int KEYCENTER = -5;
    public static final int KEYUP = -1;
    public static int KEYDOWN = 0;
    static int TRIGHT;
    static int TLEFT;
    static final int KEYSOFTLEFT = -6;
    static final String CAP_EXIT = "Keluar";
    public static final String CAP_OPEN = "Buka";
    public static final String CAP_INDEX = "Index Surah";
    public static final String CAP_MENU = "Menu Utama";
    public static final String CAP_SAVEBOOKMARK = "Simpan Bookmark";
    public static final String CAP_GOTO_AYAT = "Ke Ayat";
    static final String CAP_GOTOBOOKMARK = "Buka Bookmark";
    public static final String CAP_GOTOSTART = "Awal";
    public static final String CAP_GOTOEND = "Akhir";
    public static final String CAP_INTRO = "Pendahuluan";
    public static final String CAP_BANTUAN = "Bantuan";
    public static final String CAP_ABOUT = "Tentang";
    private boolean locked;
    private String judul;
    private String cur_url;
}
